#include "Thread.h"


bool createThread(Thread *thread, ThreadHandle handle, void *data) {
    thread->handle = handle;
    thread->data = data;
    thread->started = true;
    thread->stoped = true;
    thread->running = true;
    return true;
}

bool runThread(Thread *thread) {
     if (pthread_create(&thread->thread, NULL,thread->handle,thread->data) == 0) {
        thread->started = true;
        thread->running = true;
        thread->stoped = false;
    } else {
        thread->running = false;
        thread->stoped = true;
    }
    return thread->running;
}

// None Standard Function
bool stopThread(Thread *thread) {
    if (thread->started && thread->running) {
        if (pthread_cancel(thread->thread) == 0) {
            thread->stoped = true;
            return true;
        } else {
            return false;
        }
    }
    return true;
}